package alg20241116;

import java.util.Random;

public class Text3 {
    public static void main(String[] args) {
        Random rand = new Random();
        System.out.println(rand.nextInt());
    }
    public int[] sortArray(int[] nums) {
        int left = 0, right = nums.length-1;
        quicklySortArray(left, right, nums);
        return nums;
    }
    public static void quicklySortArray(int l, int r, int[] nums){
        if(l >= r) return;
        Random rand = new Random();
        int key = nums[rand.nextInt(r - l + 1) + l];
        int left = l - 1, right = r + 1, i = l;
        while(i < right) {
            if (nums[i] < key) swap(++left, i++, nums);
            else if (nums[i] == key) i++;
            else swap(--right, i, nums);
        }
        //
        quicklySortArray(l, left, nums);
        quicklySortArray(right, r,nums);
    }
    public static void swap(int i, int j, int[] nums){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

}
